package com.xafc.demo.security.utils;


/**
 * 保存当前登录用户信息
 * @author Admin
 */
public class UserHolderUtils {

    private static final ThreadLocal<CurrentUser> USER_HOLDER = new ThreadLocal<>();

    public static void setUser(CurrentUser user){
        USER_HOLDER.set(user);
    }

    public static CurrentUser getUser(){
        return USER_HOLDER.get();
    }

    public static Integer getUserId(){
        if(null != USER_HOLDER.get()){
            return USER_HOLDER.get().getUserId();
        }
        return null;
    }

    public static void remove(){
        USER_HOLDER.remove();
    }

}
